{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# dtype"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 概述\n",
    "\n",
    "MindSpore张量支持不同的数据类型，包含`int8`、`int16`、`int32`、`int64`、`uint8`、`uint16`、`uint32`、`uint64`、`float16`、`float32`、`float64`、`bool_`，与NumPy的数据类型一一对应。\n",
    "\n",
    "在MindSpore的运算处理流程中，Python中的`int`数会被转换为定义的`int64`类型，`float`数会被转换为定义的`float32`类型。\n",
    "\n",
    "详细的类型支持情况请参考https://www.mindspore.cn/doc/api_python/zh-CN/master/mindspore/mindspore.html#mindspore.dtype。\n",
    "\n",
    "> 本文档适用于CPU、GPU和Ascend环境。\n",
    "\n",
    "以下代码，打印MindSpore的数据类型int32。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Int32\n"
     ]
    }
   ],
   "source": [
    "from mindspore import dtype as mstype\n",
    "\n",
    "data_type = mstype.int32\n",
    "print(data_type)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 数据类型转换接口\n",
    "\n",
    "MindSpore提供了以下几个接口，实现与NumPy数据类型和Python内置的数据类型间的转换。\n",
    "\n",
    "   * `dtype_to_nptype`：将MindSpore的数据类型转换为NumPy对应的数据类型。\n",
    "\n",
    "   * `dtype_to_pytype`：将MindSpore的数据类型转换为Python对应的内置数据类型。\n",
    "\n",
    "   * `pytype_to_dtype`：将Python内置的数据类型转换为MindSpore对应的数据类型。\n",
    "\n",
    "以下代码实现了不同数据类型间的转换，并打印转换后的类型。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'numpy.int32'>\n",
      "Int64\n",
      "<class 'float'>\n"
     ]
    }
   ],
   "source": [
    "from mindspore import dtype as mstype\n",
    "\n",
    "np_type = mstype.dtype_to_nptype(mstype.int32)\n",
    "ms_type = mstype.pytype_to_dtype(int)\n",
    "py_type = mstype.dtype_to_pytype(mstype.float64)\n",
    "\n",
    "print(np_type)\n",
    "print(ms_type)\n",
    "print(py_type)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "MindSpore-1.0.1",
   "language": "python",
   "name": "mindspore-1.0.1"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
